package com.gin.kotlin.no_gay_alliance.model

import androidx.annotation.AttrRes
import com.gin.kotlin.no_gay_alliance.R
import com.gin.nga.enums.status.ReplyStatus
import com.gin.nga.enums.status.TopicStatus
import com.gin.nga.response.topic.TopicInfo

/**
 * 主题状态
 */
class TopicStatusModel(
    val name: String,
    @AttrRes
    val color: Int,
) {
    companion object {
        private val RED_TAG = listOf(
            ReplyStatus.HIDDEN,
            ReplyStatus.REPORTED,
            ReplyStatus.VERIFYING,
            ReplyStatus.VERIFYING_2,
            ReplyStatus.LOCKED,
            ReplyStatus.PUNISHED,
            ReplyStatus.NOT_VERIFIED,
        )

        private val BLUE_TAG = listOf(
            ReplyStatus.FREE_EDIT,
            ReplyStatus.SELF_REPLY,
            ReplyStatus.IS_SET,
            ReplyStatus.IS_FORUM,
            ReplyStatus.DOWN,
        )

        private val TOPIC_TAG = listOf(
            TopicStatus.REVERSED,
            TopicStatus.DOWN,
            TopicStatus.ALL_ANONYMOUS,
            TopicStatus.ALL_HIDDEN,
            TopicStatus.REPLY_ONCE,
        )

        /**
         * 从主题信息中解析主题状态
         */
        fun parse(topicInfo: TopicInfo): List<TopicStatusModel> {
            val res = mutableListOf<TopicStatusModel>()
            val replyStatuses = topicInfo.getStatus()
            RED_TAG.filter { replyStatuses?.contains(it) == true }.forEach { res.add(TopicStatusModel(it.tag, R.attr.textColorRed)) }
            BLUE_TAG.filter { replyStatuses?.contains(it) == true }.forEach { res.add(TopicStatusModel(it.tag, R.attr.textColorBlue)) }

            val topicStatus = topicInfo.getTopicStatus()
            TOPIC_TAG.filter { topicStatus.contains(it) }.forEach { res.add(TopicStatusModel(it.tag, R.attr.textColorBlue)) }

            return res
        }

    }
}